-
Notifications
You must be signed in to change notification settings - Fork 227
Support DPPL 0.37 #2550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: breaking
Are you sure you want to change the base?
Support DPPL 0.37 #2550
Conversation
That is tempting, to not waste time fixing code that's on its way out. I worry though that removing the samplers will take a while still, and in the meanwhile all the accumulator stuff, and other DPPL changes that build on it, would be held back from Turing.jl. For instance, introducing ValuesAsInModelAccumulator would cut our inference time in #2542 by half. |
IMO, it goes both ways. Reducing sampler complexity would make this PR easier. On the other hand, merging this PR would also make it easier to remove the duplicate samplers. (To be precise, DPPL 0.37 would make it easier.) I think DPPL 0.37 has taken a long time and we should prioritise this, rather than trying to squeeze in the changes to samplers. I'm going to fix the merge conflicts and add a Note that 1.10 CI will always fail as |
test/mcmc/hmc.jl
Outdated
# TODO(mhauru) Do we give up being able to sample from only prior/likelihood like this, | ||
# or do we implement some way to pass `whichlogprob=:LogPrior` through `sample`? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sample(::LogDensityFunction)
would solve that, since we could set getlogprior
in the LDF, but I guess that'll be the next release.
# TODO(penelopeysm): Can we just use leafcontext(model.context)? Do we | ||
# need to pass in the sampler? (In fact LogDensityFunction defaults to | ||
# using leafcontext(model.context) so could we just remove the argument | ||
# entirely?) | ||
DynamicPPL.SamplingContext(rng, spl, DynamicPPL.leafcontext(model.context)); | ||
adtype=spl.alg.adtype, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As established in (e.g.) TuringLang/DynamicPPL.jl#955 (comment) SamplingContext for Hamiltonians was never overloaded so it is equivalent to just use DefaultContext in the LDF.
Exactly like DynamicPPL.LogPriorAccumulator, but does not include the log determinant of the | ||
Jacobian of any variable transformations. | ||
|
||
Used for MAP optimisation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am actually quite confused as to why this is needed (and OptimizationContext before it) because if the VarInfo is linked, calling getlogp
on it won't include the logjac. (This is the source of the problem in #2617)
This would only be needed if we wanted to unconditionally ignore logjac even if the VarInfo is unlinked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I think there's a terminology mismatch here. I must be thinking of logjac of the invlink transform (and that's also what #2617 refers to), whereas this is talking about logjac of the link transform.
i.e. you want to plug in values in linked space and get the invlinked logp as the optimisation target, ignoring the logjac required to transform values to linked space.
whereas the way I've been seeing it is that we can sample in linked space but we need to make sure to include the logjac of the invlink transform so that we get the invlinked logp.
Because Turing re-exports some things that were changed in DPPL 0.37 (for example, |
4ee5649
to
4d03c07
Compare
Turing.jl documentation for PR #2550 is available at: |
This is getting too unwieldy, unfortunately. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## breaking #2550 +/- ##
=============================================
- Coverage 84.78% 24.79% -60.00%
=============================================
Files 22 22
Lines 1466 1460 -6
=============================================
- Hits 1243 362 -881
- Misses 223 1098 +875 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went through the code and highlighted with comments any bits that seemed like they weren't done.
With @penelopeysm we agreed that this PR is getting unwieldy. All the obvious interface changes should now be done. The things that don't work are getting logp from samplers, Gibbs, and particle MCMC. We should make individual PRs to fix those, merge them into this one, and then check the comments I left to make sure everything is done. Except for the comments raised, I consider the code in here currently to be ready to merge once tests pass.
@penelopeysm feel free to likewise flag any parts of the code that we must not forget to attend to before merging this. Hopefully we can then not do another review of what's here now.
[sources] | ||
DynamicPPL = {url = "https://github.com/TuringLang/DynamicPPL.jl", rev = "breaking"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must not forget to remove this.
# TODO(DPPL0.37/penelopeysm): This is obviously incorrect. Fix this. | ||
vi = DynamicPPL.setloglikelihood!!(vi, Q.ℓq) | ||
vi = DynamicPPL.setlogprior!!(vi, 0.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must not forget to fix this.
# TODO(DPPL0.37/penelopeysm) This is obviously wrong. Note that we | ||
# have the same problem here as in HMC in that the sampler doesn't | ||
# tell us about how logp is broken down into prior and likelihood. | ||
# We should probably just re-evaluate unconditionally. A bit | ||
# unfortunate. | ||
DynamicPPL.setlogprior!!(new_varinfo, 0.0) | ||
DynamicPPL.setloglikelihood!!(new_varinfo, new_logp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must not forget to fix this.
# TODO(mhauru) Fix accumulation here. In this branch anything that gets | ||
# accumulated just gets discarded with `_`. | ||
value, _ = DynamicPPL.tilde_assume( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must not forget to fix this.
# Re-evaluate to calculate log probability density. | ||
# TODO(penelopeysm): This seems a little bit wasteful. Unfortunately, | ||
# even though `t.stat.log_density` contains some kind of logp, this | ||
# doesn't track prior and likelihood separately but rather a single | ||
# log-joint (and in linked space), so which we have no way to decompose | ||
# this back into prior and likelihood. I don't immediately see how to | ||
# solve this without re-evaluating the model. | ||
_, vi = DynamicPPL.evaluate!!(model, vi) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must not forget to attend to this and make a call on whether to pay the cost of re-evaluating or live without a logp.
# TODO(DPPL0.37/penelopeysm): This is obviously incorrect. We need to | ||
# re-evaluate the model. | ||
set_namedtuple!(vi, trans.params) | ||
return setlogp!!(vi, trans.lp) | ||
vi = DynamicPPL.setloglikelihood!!(vi, trans.lp) | ||
return DynamicPPL.setlogprior!!(vi, 0.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must not forget to fix this.
# TODO(DPPL0.37/penelopeysm): This is obviously incorrect. We need to | ||
# re-evaluate the model. | ||
vi = DynamicPPL.unflatten(vi, trans.params) | ||
vi = DynamicPPL.setloglikelihood!!(vi, trans.lp) | ||
return DynamicPPL.setlogprior!!(vi, 0.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must not forget to fix this.
# TODO(DPPL0.37/penelopeysm) The whole tilde pipeline for particle MCMC needs to be | ||
# thoroughly fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must not forget to fix this.
[sources] | ||
DynamicPPL = {url = "https://github.com/TuringLang/DynamicPPL.jl", rev = "breaking"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must not forget to remove this.
Seems to me that there are several stages:
I'll go off and get started on the logjac acc, shouldn't be too hard since it's all the same code as before. |
Currently in a very unfinished state.